home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
spoolaq.exe
/
SPOOL2.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-06-12
|
18KB
|
561 lines
{************************************************}
{ }
{ program SPOOL2 }
{ demo program based on TVGUID15.PAS }
{ (Copyright (c) 1990 by Borland International)}
{ }
{ this program uses the SPOOL-tpu to print }
{ in the background }
{ }
{ this is part of SPOOL.EXE }
{************************************************}
{$V-}
{$X+}
program Spool2;
uses Objects, Drivers, Views, Menus, Dialogs, MsgBox, App, Spooler;
const
FileToRead = 'SPOOL2.PAS';
MaxLines = 100;
WinCount: Integer = 0;
cmFileOpen = 100;
cmNewWin = 101;
cmNewDialog = 102;
cmFileToSpool = 103; (* !!! added !!! *)
var
LineCount: Integer;
Lines: array[0..MaxLines - 1] of PString;
type
DialogData = record
CheckBoxData: Word;
RadioButtonData: Word;
InputLineData: string[128];
end;
TMyApp = object(TApplication)
MySpooler : PSpooler;
constructor Init;
destructor Done; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure InitMenuBar; virtual;
procedure InitStatusLine; virtual;
procedure Idle; virtual; (* !!! added !!! *)
procedure FileToSpool; (* !!! added !!! *)
procedure NewDialog;
procedure NewWindow;
end;
PInterior = ^TInterior;
TInterior = object(TScroller)
constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
procedure Draw; virtual;
end;
PDemoWindow = ^TDemoWindow;
TDemoWindow = object(TWindow)
RInterior, LInterior: PInterior;
constructor Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
function MakeInterior(Bounds: TRect; Left: Boolean): PInterior;
procedure SizeLimits(var Min, Max: TPoint); virtual;
end;
PDemoDialog = ^TDemoDialog;
TDemoDialog = object(TDialog)
end;
procedure ReadFile;
var
F: Text;
S: String;
begin
LineCount := 0;
Assign(F, FileToRead);
{$I-}
Reset(F);
{$I+}
if IOResult <> 0 then
begin
Writeln('Cannot open ', FileToRead);
Halt(1);
end;
while not Eof(F) and (LineCount < MaxLines) do
begin
Readln(F, S);
Lines[LineCount] := NewStr(S);
Inc(LineCount);
end;
Close(F);
end;
procedure DoneFile;
var
I: Integer;
begin
for I := 0 to LineCount - 1 do
if Lines[I] <> nil then DisposeStr(Lines[i]);
end;
{ TInterior }
constructor TInterior.Init(var Bounds: TRect; AHScrollBar,
AVScrollBar: PScrollBar);
begin
TScroller.Init(Bounds, AHScrollBar, AVScrollBar);
Options := Options or ofFramed;
SetLimit(128, LineCount);
end;
procedure TInterior.Draw;
var
Color: Byte;
I, Y: Integer;
B: TDrawBuffer;
begin
Color := GetColor(1);
for Y := 0 to Size.Y - 1 do
begin
MoveChar(B, ' ', Color, Size.X);
i := Delta.Y + Y;
if (I < LineCount) and (Lines[I] <> nil) then
MoveStr(B, Copy(Lines[I]^, Delta.X + 1, Size.X), Color);
WriteLine(0, Y, Size.X, 1, B);
end;
end;
{ TDemoWindow }
constructor TDemoWindow.Init(Bounds: TRect; WinTitle: String; WindowNo: Word);
var
S: string[3];
R: TRect;
begin
Str(WindowNo, S);
TWindow.Init(Bounds, WinTitle + ' ' + S, wnNoNumber);
GetExtent(Bounds);
R.Assign(Bounds.A.X, Bounds.A.Y, Bounds.B.X div 2 + 1, Bounds.B.Y);
LInterior := MakeInterior(R, True);
LInterior^.GrowMode := gfGrowHiY;
Insert(Linterior);
R.Assign(Bounds.B.X div 2, Bounds.A.Y, Bounds.B.X, Bounds.B.Y);
RInterior := MakeInterior(R,False);
RInterior^.GrowMode := gfGrowHiX + gfGrowHiY;
Insert(RInterior);
end;
function TDemoWindow.MakeInterior(Bounds: TRect; Left: Boolean): PInterior;
var
HScrollBar, VScrollBar: PScrollBar;
R: TRect;
begin
R.Assign(Bounds.B.X-1, Bounds.A.Y+1, Bounds.B.X, Bounds.B.Y-1);
VScrollBar := New(PScrollBar, Init(R));
VScrollBar^.Options := VScrollBar^.Options or ofPostProcess;
if Left then VScrollBar^.GrowMode := gfGrowHiY;
Insert(VScrollBar);
R.Assign(Bounds.A.X+2, Bounds.B.Y-1, Bounds.B.X-2, Bounds.B.Y);
HScrollBar := New(PScrollBar, Init(R));
HScrollBar^.Options := HScrollBar^.Options or ofPostProcess;
if Left then HScrollBar^.GrowMode := gfGrowHiY + gfGrowLoY;
Insert(HScrollBar);
Bounds.Grow(-1,-1);
MakeInterior := New(PInterior, Init(Bounds, HScrollBar, VScrollBar));
end;
procedure TDemoWindow.SizeLimits(var Min, Max: TPoint);
var R: TRect;
begin
TWindow.SizeLimits(Min, Max);
Min.X := LInterior^.Size.X + 9;
end;
{ TMyApp }
constructor TMyApp.Init;
var
Rectangle : TRect;
begin
TApplication.Init;
MySpooler := nil;
end;
destructor TMyApp.Done;
begin
TApplication.Done;
if MySpooler<>nil then
Dispose( MySpooler, Done);
end;
procedure TMyApp.HandleEvent(var Event: TEvent);
begin
TApplication.HandleEvent(Event);
if Event.What = evCommand then
begin
case Event.Command of
cmNewWin: NewWindow;
cmNewDialog: NewDialog;
cmFileToSpool : FileToSpool; (* !!! added !!! *)
else
Exit;
end;
ClearEvent(Event);
end;
end;
procedure TMyApp.InitMenuBar;
var R: TRect;
begin
GetExtent(R);
R.B.Y := R.A.Y + 1;
MenuBar := New(PMenuBar, Init(R, NewMenu(
NewSubMenu('~F~ile', hcNoContext, NewMenu(
NewItem('~O~pen', 'F3', kbF3, cmFileOpen, hcNoContext,
NewItem('~N~ew', 'F4', kbF4, cmNewWin, hcNoContext,
NewLine(
(* added: the new entry in the menu: *)
NewItem('~S~tart Spooling', '', 0, cmFileToSpool, hcNoContext,
NewLine(
NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
nil))))))),
NewSubMenu('~W~indow', hcNoContext, NewMenu(
NewItem('~N~ext', 'F6', kbF6, cmNext, hcNoContext,
NewItem('~Z~oom', 'F5', kbF5, cmZoom, hcNoContext,
NewItem('~D~ialog', 'F2', kbF2, cmNewDialog, hcNoContext,
nil)))),
nil))
)));
end;
procedure TMyApp.InitStatusLine;
var R: TRect;
begin
GetExtent(R);
R.A.Y := R.B.Y - 1;
StatusLine := New(PStatusLine, Init(R,
NewStatusDef(0, $FFFF,
NewStatusKey('', kbF10, cmMenu,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
NewStatusKey('~F4~ New', kbF4, cmNewWin,
NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
nil)))),
nil)
));
end;
(* ╔════════════════════════════════════════════════════════════════╗ *)
(* ║ ║ *)
(* ║ added: output the data to the printer ║ *)
(* ║ ║ *)
(* ╚════════════════════════════════════════════════════════════════╝ *)
procedure TMyApp.Idle;
begin
TApplication.Idle;
if MySpooler<>nil then
MySpooler^.SpoolOneChar;
end; (* ------------------------------------------- Idle *)
(* ╔════════════════════════════════════════════════════════════════╗ *)
(* ║ ║ *)
(* ║ added: which file to spool, which port to use etc. ║ *)
(* ║ ║ *)
(* ╚════════════════════════════════════════════════════════════════╝ *)
procedure TMyApp.FileToSpool;
type
SpoolDlgData = record
FileName : string[64];
Port : word;
HWAccess : word;
Baud : word;
Data : word;
Stop : word;
Parity : word;
FlowControl : word;
end;
var
Dialog : PDialog;
FileName : PInputLine;
Rectangle : TRect;
Button : PButton;
RadioButtons : PRadioButtons;
Text : PStaticText;
LabelText : PLabel;